<?php

/**
 * @author Samrat Khan & Sadik Sarfaraz - 4:19:44 PM Jul 14, 2013 
 */

require('top.inc.php');
$formLoad = new Form();
if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1 || $_SESSION['user']['utype'] == 2 || $_SESSION['user']['utype'] == 3 || $_SESSION['user']['utype'] == 4) {
    $sess_userID = $_SESSION['user']['id'];
    if($_GET['stockout_id']) {
        $stockout_id = $_GET['stockout_id'];
        echo '<form name="ModifyStockOut" id="modifyStockOut" method="post" action="modify.php">';
            echo "<table class=\"form-inline row-fluid table table-striped table-bordered\">";
            echo "<tr>";
                echo "<th>" . $stock_out['serialno'] . "</th>";
                echo "<th>" . $stock_out['challannumber'] . "</th>";
                echo "<th>" . $stock_out['siteid'] . "</th>";
                echo "<th>" . $stock_out['deliverytime'] . "</th>";
                echo "<th>" . $stock_out['receivername'] . "</th>";
                echo "<th>" . $stock_out['cellnumber'] . "</th>";
                echo "<th>" . $stock_out['remarks'] . "</th>";
                echo "<th>" . "&nbsp;" . "</th>";
            echo "</tr>";

            $row = selectSingle($stockout_id, $db);
            foreach ($row as $single) {
                echo "<tr>";
                    echo "<td>" . $formLoad->textFieldReadyOnly('serialno', 'serialno', 'serialno', $readonly, '', $single['serialno']) . "</td>";
                    echo "<td>" . $formLoad->textField('challannumber', 'challannumber', 'challannumber', '', $single['challannumber']) . "</td>";
                    echo "<td>" . $formLoad->textField('siteid', 'siteid', 'siteid', '', $single['siteid']) . "</td>";
                    echo "<td>" . $formLoad->textFieldDate('deliverytime', "input-append date", "deliverytime", "deliverytimeID", '', $single['deliverytime']) . "</td>";
                    echo "<td>" . $formLoad->textField('receivername', "", "receivername", '', $single['receivername']) . "</td>";
                    echo "<td>" . $formLoad->textField('cellnumber', "", "cellnumber", '', $single['cellnumber']) . "</td>";
                    echo "<td>" . $formLoad->textField('remarks', "", "remarks", '', $single['remarks']) . "</td>";
                    echo "<input type='hidden' name='stockout_id' value='".$single['stockout_id']."' />";
                    echo "<td>";
                        echo '<input id="ModifyStockOutBtn" class="btn btn-primary" type="submit" value="Save Info" name="modifyStockOut" />';
                    echo "</td>";
                echo "</tr>";
            }
        echo "<table>";
        echo '</form>';
    } else {
        
    $sess_userID = $_SESSION['user']['id'];
    $rows1 = modifyStockout($sess_userID, $db);

    echo "<table class=\"form-inline row-fluid table table-striped table-bordered\">";
        echo "<tr>";
            echo "<th>" . $optionsIcons['option'] . "</th>";
            echo "<th>" . $stock_out['serialno'] . "</th>";
            echo "<th>" . $stock_out['productid'] . "</th>";
            echo "<th>" . $stock_out['boxno'] . "</th>";
            echo "<th>" . $stock_out['description'] . "</th>";
            echo "<th>" . $stock_out['eng_id'] . "</th>";
            echo "<th>" . $stock_out['responsetype'] . "</th>";
            echo "<th>" . $stock_out['revisionstate'] . "</th>";
            echo "<th>" . $stock_out['challannumber'] . "</th>";
            echo "<th>" . $stock_out['out_quantity'] . "</th>";
            echo "<th>" . $stock_out['uom'] . "</th>";
            echo "<th>" . $stock_out['requestnumber'] . "</th>";
            echo "<th>" . "Cancel" . "</th>";
            echo "<th>" . $stock_out['requestedby'] . "</th>";
            echo "<th>" . $stock_out['siteid'] . "</th>";
            echo "<th>" . $stock_out['project_id'] . "</th>";
            echo "<th>" . $stock_out['requesttime'] . "</th>";
            echo "<th>" . $stock_out['deliverytime'] . "</th>";
            echo "<th>" . $stock_out['receivedtime'] . "</th>";
            echo "<th>" . $stock_out['sla'] . "</th>";
            echo "<th>" . $stock_out['receivername'] . "</th>";
            echo "<th>" . $stock_out['cellnumber'] . "</th>";
            echo "<th>" . $stock_out['warehouseid'] . "</th>";
            echo "<th>" . $stock_out['transportername'] . "</th>";
            echo "<th>" . $stock_out['employee_id'] . "</th>";
            echo "<th>" . $stock_out['remarks'] . "</th>";
            echo "<th>" . $stock_out['user_id'] . "</th>";
            echo "<th>" . $stock_out['cus_id'] . "</th>";
            echo "<th>" . $stock_out['inserteddate'] . "</th>";
        echo "</tr>";
    foreach ($rows1 as $row) {
        echo "<tr>";
            echo "<td>";
            echo "<a class='btn btn-success btn-mini' href='modify-stockout.php?stockout_id={$row['stockout_id']}'>" . $optionsIcons['update'] . "</a>";
            echo "</td>";
            echo "<td>" . $row['serialno'] . "</td>";
            echo "<td>" . $row['productid'] . "</td>";
            echo "<td>" . $row['boxno'] . "</td>";
            echo "<td>" . $row['description'] . "</td>";
            echo "<td>" . getName('engineerinfo', 'engname', 'eng_id', $row['eng_id'], $db) . "</td>";
            echo "<td>" . getName('responsetype', 'uniquename', 'responsetype_id', $row['response_type_id'], $db) . "</td>";
            echo "<td>" . $row['revisionstate'] . "</td>";
            echo "<td>" . $row['challannumber'] . "</td>";
            echo "<td>" . $row['out_quantity'] . "</td>";
            echo "<td>" . getName('uom', 'measurement', 'uom_id', $row['uom'], $db) . "</td>";
            echo "<td>" . $row['requestnumber'] . "</td>";
            echo "<td>" . "<a class='btn btn-danger' href='javascript:void(0)' onclick='addCanceled(" . $row["stockout_id"] . ")'>Cancel</a> " . "</td>";
            echo "<td>" . $row['requestedby'] . "</td>";
            echo "<td>" . $row['siteid'] . "</td>";
            echo "<td>" . getName('projects', 'projectname', 'project_id', $row['project_id'], $db) . "</td>";
            echo "<td>" . $row['requesttime'] . "</td>";
            echo "<td>" . $row['deliverytime'] . "</td>";
            echo "<td>" . $row['receivedtime'] . "</td>";
            echo "<td>" . $row['sla'] . "</td>";
            echo "<td>" . $row['receivername'] . "</td>";
            echo "<td>" . $row['cellnumber'] . "</td>";
            echo "<td>" . getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouseid'], $db) . "</td>";
            echo "<td>" . $row['transportername'] . "</td>";
            echo "<td>" . getName('employee', 'employeename', 'employee_id', $row['employee_id'], $db) . "</td>";
            echo "<td>" . $row['remarks'] . "</td>";
            echo "<td>" . getName('wms_users', 'username', 'id', $row['userid'], $db) . "</td>";
            echo "<td>" . getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) . "</td>";
            echo "<td>" . $row['inserteddate'] . "</td>";
        echo "</tr>";
    }
    echo "<table>";    
    }
}
?>
